package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.CurriculumSeries;
import cn.wolfcode.crm.query.QueryForObject;
import cn.wolfcode.crm.service.ICurriculumSeriesService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("curriculumSeries")
public class CurriculumSeriesController {
    @Autowired
    private ICurriculumSeriesService curriculumSeriesService;

    /*创建一个方法来确定*/
    @RequiresPermissions("curriculumSeries:index")
    @PermissionName("课程系列首页")
    @RequestMapping("index")
    public String index(){
        //查找到并共享
        return "curriculumSeries/list";
    }
    @RequiresPermissions("curriculumSeries:list")
    @PermissionName("课程系列列表")
    @ResponseBody
    @RequestMapping("list")
    public PageResult list(Model model, @ModelAttribute("qo")QueryForObject qo){
        return curriculumSeriesService.query(qo);
    }

    /**
     *
     * @param curriculumSeries 保存课程系列
     * @return 返回json
     */
    @RequiresPermissions("curriculumSeries:save")
    @PermissionName("课程系列保存")
    @ResponseBody
    @RequestMapping("save")
    public JsonResult save(CurriculumSeries curriculumSeries){
        JsonResult result = new JsonResult();
        try {
            curriculumSeriesService.insert(curriculumSeries);
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("保存失败");
        }
        return result;
    }
    @RequiresPermissions("curriculumSeries:update")
    @PermissionName("课程系列更新")
    @ResponseBody
    @RequestMapping("update")
    public JsonResult update(CurriculumSeries curriculumSeries){
        JsonResult result = new JsonResult();
        try {
            curriculumSeriesService.updateByPrimaryKey(curriculumSeries);
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("更新失败");
        }
        return result;
    }
    //删除课程系列
    @RequiresPermissions("curriculumSeries:delete")
    @PermissionName("课程系列删除")
    @ResponseBody
    @RequestMapping("delete")
    public JsonResult delete(Long id){
        JsonResult result = new JsonResult();
        try {
            curriculumSeriesService.deleteByPrimaryKey(id);
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("删除失败");
        }
        return result;
    }
    @RequiresPermissions("curriculumSeries:selectAll")
    @PermissionName("课程系列列表")
    @ResponseBody
    @RequestMapping("selectAll")
    public List<CurriculumSeries> selectAll(){
        return curriculumSeriesService.selectAll();
    }


}
